package com.wswy.wzcx.statistics;

import android.content.Context;
import android.util.Log;
import com.baidu.mobstat.StatService;
import com.wswy.wzcx.AppContext;
import com.wswy.wzcx.BuildConfig;
import java.util.Collections;
import java.util.Map;

/**
 * Created by wangduheng26 on 2018/3/21.
 * wangduheng26@gmail.com
 */

public class StatTools {

    private static final String TAG = "StatTools";

    public static void sendClick(Context context,String eventId){
        StatService.onEvent(context,eventId,"click",1);
        //Log.e(TAG, "sendClick --> "+eventId);
    }

    public static void sendShow(Context context,String eventId){
        sendShow(context,eventId,"result");
    }
    public static void sendShow(Context context,String eventId,String label){
        StatService.onEvent(context,eventId,label,1);
        //Log.e(TAG, "sendShow --> "+eventId+"  " +label);

    }

    public static void sendClickNew(Context context,String label,int position){
        sendClickNew(context,StatisticsId.click_News,label,position);
    }

    public static void sendClickNew(Context context,String type ,String label,int position){
        Map<String, String> list = Collections.singletonMap("list", label + ( position > 10 ? "_more": "_"+position) );

        StatService.onEvent(context,type,label,1,list);
    }

    public static void sendEvent(Context context,String type ,String label,String param){
        Map<String, String> list = Collections.singletonMap("list", param);
        StatService.onEvent(context,type,label,1,list);
    }



    public static void sendPageStart(Context context,String pageName){
        StatService.onPageStart(context,pageName);
    }
    public static void sendPageEnd(Context context,String pageName){
        StatService.onPageEnd(context,pageName);
    }






    //////
    public static void sendGovEvent(String label,boolean status){
        Map<String, String> list = Collections.singletonMap("list", label+(status?"_ok":"_error"));

        if (BuildConfig.DEBUG){
            Log.e(TAG,"sendGovEvent --->"+label+"  "+list);
        }

        StatService.onEvent(AppContext.getContext(),StatisticsId.gw_122,label,1,list);
    }

    public static void sendGovTime(String label,long time){

        if (BuildConfig.DEBUG){
            Log.e(TAG,"sendGovTime --->"+label+"  time:"+time);
        }

        StatService.onEventDuration(AppContext.getContext(),StatisticsId.gw_122_time,label,time);
    }

}
